package cn.humaohua.study.yanmo_design_pattern.ch21;

import org.w3c.dom.Element;

public class ElementTerminalExpression extends ReadXmlExpression {
    private String eleName = "";

    public ElementTerminalExpression(String eleName) {
        this.eleName = eleName;
    }

    @Override
    public String[] interpret(Context c) {
        Element pEle = c.getPreEle();
        Element ele = null;
        if (pEle == null) {
            ele = c.getDocument().getDocumentElement();
            c.setPreEle(ele);
        } else {
            ele = c.getNowEle(pEle, eleName);
            c.setPreEle(ele);
        }

        String[] ss = new String[1];
        ss[0] = ele.getFirstChild().getNodeValue();
        return ss;
    }
}
